
//获取新增/编辑页面
function getAddressHtml(address_id){
    $.ajax({
        url:"/index.php?m=Home&c=Address&a=edit_address",
        data:{'address_id':address_id}, 
        type:'get',
        datatype:'html',
        success:function(data){
            $(".add_addr").html(data);
        }
    })
};
//一开始就加载页面
getAddressHtml(0);

//todo 点击选择收货地址，显示弹框
$(".address").click(function(){
    $("#receiveAddrTk").show();
    $(".selectAddr").show();
    $(".selectAddr").css("bottom",0)
});

//选择收货地址 selected
$(".selectAddr li>div:first-child").click(function(){
    if(!$(this).hasClass("selected")){
        $(".selectAddr li>div:first-child").removeClass("selected");
        $(this).addClass("selected");
        $("#receiveAddrTk").hide();
        $(".addressee_infor2").hide();
        $(".addressee_infor1").show();
        var name=$(this).next().find("span.name").text();
        var phone=$(this).next().find("span.phone").text();
        var address=$(this).next().find("div.dizhi").text();
        var address_id=$(this).next().find("div.slect_address_id").text();
        $("body>.top").empty();
        var s = "<div class='info'><span>收货人："+name+"</span><span class='rt'>"+phone+"</span></div><div class='addr'><i></i><span>"+address+"</span><u class='rt'></u></div>";
        $('body>.top').append(s);
        $("body>#address_id").val(address_id);
    }
});

//选择收货地址关闭按钮
$(".selectAddr .top>i").click(function(){
    var height=$(".selectAddr").height();
    $(".selectAddr").animate({
        bottom:"-"+height
    },400);
    setTimeout(function(){$("#receiveAddrTk").hide()},500);
});

//todo 新建地址按钮
$(".selectAddr>div:last-child").click(function(){
    $(".selectAddr").hide();
    $("#receiveAddrTk").show();
    $(".add_addr").show().animate({bottom:0},500);
});

//编辑地址页面
function edit_address(address_id){
    getAddressHtml(address_id);
    $("#receiveAddrTk").show();
    $(".add_addr").show().animate({bottom:0},500);
};

//新增地址关闭按钮
$("#receiveAddrTk").on("click","i.close",function(){
    $(".warn").show();
    $(".warn .cancel").click(function(){$(".add_addr .warn").hide()});
    $(".warn .sure").click(function(){
        var height=$(".add_addr").height();
        $(".add_addr .warn").hide();
        $(".add_addr").animate({bottom:"-"+height},400);
        $(".selectAddr").show();
    });
});


